﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class GameSystem
    {
        
            public bool Gaming(Hero hero, User user)
            {
                int sum = 0;
                int hNum = 0;
                int uNum = 0;
                while (true)
                {
                    string heroAction;
                    string userAction;
                    userAction = user.Action();
                    Console.WriteLine(user.Name + ": 出拳：  " + userAction);
                    heroAction = hero.Action();
                    Console.WriteLine(hero.Name + ": 出拳：  " + heroAction);
                    Console.WriteLine(IsWin(heroAction, userAction, user.Name, ref hNum, ref uNum));
                    sum++;
                    while (true)
                    {
                        Console.WriteLine("是否开始下一轮？（1.继续/0.停止）");
                        string chioce = Console.ReadLine();
                        if (chioce == "1")
                        {
                            break;
                        }
                        else if (chioce == "0")
                        {
                            return EndGame(hero.Name, user.Name, sum, hNum, uNum);
                        }
                        else
                        {
                            Console.WriteLine("输入错误，请重新输入");
                            continue;
                        }
                    }
                }
            }

            private bool EndGame(string heroName, string userName, int sum, int hNum, int uNum)
            {
                Console.WriteLine("===================================");
                Console.WriteLine("对战次数：" + sum);

                Console.WriteLine("姓名\t得分");
                Console.WriteLine(heroName + "\t" + hNum);
                Console.WriteLine(userName + "\t" + uNum);
                if (hNum > uNum)
                {
                    Console.WriteLine($"{heroName}赢了，{userName}输了");
                }
                else if (hNum < uNum)
                {
                    Console.WriteLine($"{userName}赢了，{heroName}输了");
                }
                else
                {
                    Console.WriteLine("平局");
                }
                while (true)
                {
                    Console.WriteLine("要开始下一局吗？（y/n）");
                    string chioce = Console.ReadLine();
                    switch (chioce)
                    {
                        case "y":
                            return true;
                        case "n":
                            return false;
                        default:
                            Console.WriteLine("选择错误，请重新输入");
                            continue;
                    }
                }
            }

            public string IsWin(string A, string B, string name, ref int hNum, ref int uNum)
            {
                string str;
                if ((A == "剪刀" && B == "布") || (A == "石头" && B == "剪刀") || A == "布" && B == "石头")
                {
                    hNum++;
                    str = "赢";
                }
                else if (A == B)
                {

                    str = "平局";
                }
                else
                {
                    uNum++;
                    str = "输";
                }
                if (str == "赢")
                {
                    return $"笨蛋，{name}输了";

                }
                else if (str == "输")
                {
                    return $"恭喜，{name}赢了";
                }
                else
                {
                    return "平局，再来";
                }

                /*            else if (A == "石头" && B == "剪刀")
                            {
                                if ()
                                {
                                    hNum++;
                                    return $"笨蛋，{name}输了";
                                }
                                else if (B == "布")
                                {
                                    uNum++;
                                    return $"恭喜，{name}赢了";
                                }
                            }
                            else if (A == "布" && B == "剪刀")
                            {
                                uNum++;
                                return $"恭喜，{name}赢了";
                            }
                            else if (A == "布" && B == "石头")
                            {
                                hNum++;
                                return $"笨蛋，{name}输了";
                            }
                            else*/

            }

        
    }
}
